<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report name" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1bed67d9-e402-4090-83cd-921e333957e0">
	<property name="ireport.zoom" value="1.0"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<parameter name="sdate" class="java.lang.String"/>
	<parameter name="fdate" class="java.lang.String"/>
	<parameter name="sd" class="java.util.Date"/>
	<parameter name="fd" class="java.util.Date"/>
	<parameter name="user" class="java.lang.String"/>
	<parameter name="user_id" class="java.lang.Long"/>
	<queryString language="SQL">
		<![CDATA[SELECT
     (SELECT count(*)
        FROM
             `clients` c JOIN `clients_authorization` ca ON c.`clients_authorization_id` = ca.`id`
        WHERE
             c.state_in<>0 AND c.`stand_time` BETWEEN '$P!{sdate} 00:00:00'  AND '$P!{fdate} 23:59:59' AND c.`clients_authorization_id` IS NOT NULL AND c.`service_id`=$P{user_id}) as all_count,
      ca.`id` AS clientid,
     c.`id` AS idd,
     DATE_FORMAT(c.`stand_time`, '%d.%m.%Y %H:%i') AS stand_time,
     (SELECT sum(s.`client_wait_period`) FROM `clients` c JOIN `statistic` s ON c.`id` = s.`client_id` WHERE c.state_in<>0 AND  idd=s.`client_id` AND c.`stand_time` BETWEEN '$P!{sdate} 00:00:00'  AND '$P!{fdate} 23:59:59' AND c.`clients_authorization_id` IS NOT NULL AND c.`service_id`=$P{user_id}) AS wait_period,
     ca.`surname` AS surname,
     ca.`name` AS name,
     c.`service_prefix` AS prefix,
      c.`number` AS number
FROM
     `clients` c JOIN `clients_authorization` ca ON c.`clients_authorization_id` = ca.`id`
WHERE
    c.state_in<>0 AND c.`stand_time` BETWEEN '$P!{sdate} 00:00:00'  AND '$P!{fdate} 23:59:59' AND c.`clients_authorization_id` IS NOT NULL AND c.`service_id`=$P{user_id}
GROUP BY ca.`id`
ORDER BY c.`stand_time`]]>
	</queryString>
	<field name="surname" class="java.lang.String"/>
	<field name="all_count" class="java.lang.Integer"/>
	<field name="clientid" class="java.lang.Long"/>
	<field name="name" class="java.lang.String"/>
	<field name="stand_time" class="java.lang.String"/>
	<field name="wait_period" class="java.lang.String"/>
	<field name="prefix" class="java.lang.String"/>
	<field name="number" class="java.lang.String"/>
	<variable name="all_count" class="java.lang.Integer" calculation="Count">
		<variableExpression><![CDATA[$F{all_count}]]></variableExpression>
		<initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression>
	</variable>
	<variable name="N" class="java.lang.Integer" calculation="Count">
		<variableExpression><![CDATA[$F{clientid}]]></variableExpression>
		<initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression>
	</variable>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="91">
			<line>
				<reportElement uuid="cd6624bd-a769-4462-80fe-2f154b2301a1" x="0" y="8" width="555" height="1"/>
			</line>
			<line>
				<reportElement uuid="02c17142-22a1-4ae8-94e5-f33a639798d0" positionType="FixRelativeToBottom" x="1" y="86" width="555" height="1"/>
			</line>
			<staticText>
				<reportElement uuid="029cef7f-097e-46c3-8ad6-5507020de8e7" x="1" y="9" width="551" height="26"/>
				<textElement textAlignment="Center">
					<font size="18" isBold="true" isStrikeThrough="false" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Отчет по авторизованным персонам за период]]></text>
			</staticText>
			<textField pattern="">
				<reportElement uuid="3218f961-9580-4162-a4a1-7635f2fd7efd" x="1" y="35" width="551" height="24"/>
				<textElement textAlignment="Center">
					<font fontName="SansSerif" size="18" isBold="true" isUnderline="false" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA["с даты " + (new java.text.SimpleDateFormat("dd.MM.yyyy")).format($P{sd}) + " по дату " + (new java.text.SimpleDateFormat("dd.MM.yyyy")).format($P{fd})]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="04fb9581-c8b4-4975-9511-a8e7382bfc7c" x="1" y="59" width="551" height="24"/>
				<textElement textAlignment="Center">
					<font fontName="SansSerif" size="18" isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA["для услуги \"" + $P{user} +"\""]]></textFieldExpression>
			</textField>
		</band>
	</title>
	<pageHeader>
		<band height="13" splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="44" splitType="Stretch">
			<staticText>
				<reportElement uuid="433f9e8b-bc47-463e-8380-e61804bcd8b2" mode="Opaque" x="1" y="12" width="113" height="30" backcolor="#CCCCFF"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="koi8-r" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Время]]></text>
			</staticText>
			<staticText>
				<reportElement uuid="35290414-ed1a-48f5-a8ee-1a0791404fc8" mode="Opaque" x="114" y="12" width="56" height="30" backcolor="#CCCCCC"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="koi8-r" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Ожидание (мин)]]></text>
			</staticText>
			<staticText>
				<reportElement uuid="7ad73af1-680c-4982-9a1a-e5fb9c0eabf4" mode="Opaque" x="170" y="12" width="126" height="30" backcolor="#CCCCFF"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="koi8-r" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Документ]]></text>
			</staticText>
			<staticText>
				<reportElement uuid="df9b79e7-47a8-474e-857f-3405e27a4046" mode="Opaque" x="296" y="12" width="54" height="30" backcolor="#CCCCCC"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="koi8-r" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Номер]]></text>
			</staticText>
			<staticText>
				<reportElement uuid="f6377249-a4a0-4779-91ec-c2fb35641b78" mode="Opaque" x="350" y="12" width="205" height="30" backcolor="#CCCCFF"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="koi8-r" isPdfEmbedded="true"/>
				</textElement>
				<text><![CDATA[Клиент]]></text>
			</staticText>
			<line>
				<reportElement uuid="7b9c261e-8e45-4938-a30c-396de612b8eb" x="0" y="11" width="555" height="1"/>
			</line>
			<line>
				<reportElement uuid="98b6ed95-1d80-409c-acd0-1a7505bcaeaa" x="0" y="43" width="555" height="1"/>
			</line>
		</band>
	</columnHeader>
	<detail>
		<band height="21" splitType="Stretch">
			<line>
				<reportElement uuid="7b7a8ddb-1829-4f48-9bf7-38460714814f" x="0" y="20" width="555" height="1"/>
			</line>
			<textField>
				<reportElement uuid="328ea533-891b-47c3-9bf6-c5538f4f40ea" mode="Transparent" x="350" y="1" width="205" height="18"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{surname}+" "+$F{name}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="4b2e7c4a-8ba1-42d2-8847-b38ad34b8ebc" mode="Transparent" x="1" y="1" width="113" height="18"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{stand_time}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="e69ca4a0-7c09-41b3-a227-4853f03a2890" mode="Transparent" x="170" y="1" width="126" height="18"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[""+$F{clientid}+""]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="56a48e49-d82f-4d02-a64b-d65d57b7d0a2" mode="Opaque" x="114" y="1" width="56" height="18" backcolor="#CCCCCC"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[""+$F{wait_period}+""]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="51b8bd86-a203-4fbb-b4f0-be3e10420795" mode="Opaque" x="296" y="1" width="54" height="18" backcolor="#CCCCCC"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{prefix}+$F{number}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="45" splitType="Stretch">
			<textField>
				<reportElement uuid="7383664d-ffa7-44f9-bea5-08382cf28146" x="0" y="0" width="555" height="20"/>
				<textElement textAlignment="Center">
					<font size="14" isBold="true" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA["Общее количество клиентов за период: "+$V{all_count}]]></textFieldExpression>
			</textField>
		</band>
	</columnFooter>
	<pageFooter>
		<band height="41" splitType="Stretch">
			<textField evaluationTime="Report" pattern="" isBlankWhenNull="false">
				<reportElement uuid="02fe7859-324f-4c65-b4ff-176d6083ab0a" key="textField" x="526" y="12" width="36" height="19" forecolor="#000000" backcolor="#FFFFFF"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement>
					<font fontName="SansSerif" size="10" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<textField pattern="" isBlankWhenNull="false">
				<reportElement uuid="2dca24b8-3f25-4252-8474-f85ec3077838" key="textField" x="306" y="12" width="216" height="19" forecolor="#000000" backcolor="#FFFFFF"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement textAlignment="Right">
					<font fontName="SansSerif" size="10" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA["Страница " + $V{PAGE_NUMBER} + " из "]]></textFieldExpression>
			</textField>
			<textField pattern="" isBlankWhenNull="false">
				<reportElement uuid="9cf59c96-62c7-4078-a550-cb045a39269c" key="textField" x="11" y="12" width="209" height="19" forecolor="#000000" backcolor="#FFFFFF"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement>
					<font fontName="SansSerif" size="10" pdfFontName="tahoma.ttf" pdfEncoding="KOI8-R" isPdfEmbedded="true"/>
				</textElement>
				<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
			</textField>
		</band>
	</pageFooter>
	<summary>
		<band height="17" splitType="Stretch"/>
	</summary>
</jasperReport>
